﻿Public Class frmConfigEdit
    Public Setting As String
    Public Value As String
    Public Result As MsgBoxResult
    Private Sub btnOK_Click(sender As System.Object, e As System.EventArgs) Handles btnOK.Click
        Setting = Trim(cmbSetting.Text)
        Value = Trim(txtValue.Text)
        If Not Setting = "" Then
            Result = MsgBoxResult.Ok
            Me.Close()
        End If
    End Sub

    Private Sub btnCancel_Click(sender As System.Object, e As System.EventArgs) Handles btnCancel.Click
        Result = MsgBoxResult.Cancel
        Me.Close()
    End Sub


    Public Sub AutoComplete(ByRef cb As ComboBox, ByVal e As System.Windows.Forms.KeyPressEventArgs, Optional ByVal blnLimitToList As Boolean = False)

        Dim strFindStr As String

        If e.KeyChar = Chr(8) Then 'Check For Backspace
            If cb.SelectionStart <= 1 Then
                cb.Text = ""
                Exit Sub
            End If

            If cb.SelectionLength = 0 Then
                strFindStr = cb.Text.Substring(0, cb.Text.Length - 1)
            Else
                strFindStr = cb.Text.Substring(0, cb.SelectionStart - 1)
            End If
        Else
            If cb.SelectionLength = 0 Then
                strFindStr = cb.Text & e.KeyChar
            Else
                strFindStr = cb.Text.Substring(0, cb.SelectionStart) & e.KeyChar
            End If
        End If

        Dim intIdx As Integer = -1

        'Search the string in the ComboBox List.
        intIdx = cb.FindString(strFindStr)
        If intIdx <> -1 Then ' String found in the List.
            cb.SelectedText = ""
            cb.SelectedIndex = intIdx
            cb.SelectionStart = strFindStr.Length
            cb.SelectionLength = cb.Text.Length
            e.Handled = True
        Else
            If blnLimitToList = True Then
                e.Handled = True
            Else
                e.Handled = False
            End If
        End If
    End Sub


    Private Sub cmbSetting_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles cmbSetting.KeyPress
        AutoComplete(cmbSetting, e, False)
    End Sub

    Private Sub frmConfigEdit_Activated(sender As Object, e As System.EventArgs) Handles Me.Activated

    End Sub

    Private Sub frmConfigEdit_Load(sender As Object, e As System.EventArgs) Handles Me.Load
    End Sub
End Class